home *** CD-ROM | disk | FTP | other *** search
- {Copyright (C) 1990 by J. Scott Sanbar. All Rights Reserved}
-
- {LptInit initializes a printer and returns its status. }
- {I have found using BIOS Interrupt $17 to be unreliable }
- {in cases where a printer is disconnected or has a bad }
- {cable. This program seems more reliable and diagnostic. }
-
- {This program is hereby committed to the public domain and }
- {may be altered, used and distributed freely by all. }
-
- {$M 1024,0,0}
- {$S-}
-
- program LptInit;
-
- var
- Choice : string;
- LptPort : byte;
- Status, Control : byte;
- BaseAddress : word;
- Ticks : word absolute $0040:$006C; {Low word of timer ticks}
- StartTicks,TTLTicks : word;
-
- begin
- writeln;
- write('Which Lpt Port (1, 2 or 3)? ');
- Choice := 'G';
- readln(Choice);
- LptPort := Ord(Choice[1]) - 48;
- if (LptPort > 3) or (LptPort < 1) then begin writeln('Aborted');halt end;
- BaseAddress := MemW[$0040:6 + LptPort * 2]; {Base address to access parallel port registers}
- repeat until Ticks < $65262; {If we are too close to hour mark, wait for turnover}
- Control := Port[BaseAddress + 2]; {Read in control register}
- Port[BaseAddress + 2] := Control and $FB; {Toggle reset line on}
- Port[BaseAddress + 2] := Control; {Toggle off}
- StartTicks := Ticks; {Start counting ticks}
- repeat until (Port[BaseAddress + 1] and $80 = $80) or
- (Ticks - StartTicks > 182); {Wait until not busy or timeout (10 seconds)}
- TTLTicks := Ticks - StartTicks; {Get total time busy}
- Status := Port[BaseAddress + 1]; {Get status register}
- if Status = $00 then writeln('Invalid Printer Port') else
- if TTLTicks < 2 then writeln('Printer off or cable disconnected') else {If not busy at all, bad cable or printer off}
- if Status and $20 = $20 then writeln('Printer out of Paper') else
- if Status and $B8 = $98 then begin writeln('Printer Online');halt;end else {printer OK, exit without error code}
- writeln('Printer Off Line'); {This means printer is on, connected and has paper but is offline}
- Halt(255); {Printer not ready - exit with error code}
- end.